<template>
	<div id="NumMoney">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><h1><i class="el-icon-lx-cascades"></i> 数字转金额（将数字转换为金额）</h1></el-breadcrumb-item>				
            </el-breadcrumb>
        </div>
		<el-row>
			<el-col :span="12" class="qrcol">
				<el-card :body-style="{ padding: '0px' }">
					<el-input type="textarea" :autosize="{ minRows: 10, maxRows: 10}" v-model="inputVal" placeholder="请输入内容">
					</el-input>
				</el-card>
			</el-col>
			<el-col :span="12">
				<el-card :body-style="{ padding: '0px' }">				
					{{inputVal | toChies}}
				</el-card>
			</el-col>
		</el-row>		
		<!--过滤器-->
		<h5>数字：零, 壹, 贰, 叁, 肆, 伍, 陆, 柒, 捌, 玖</h5>
		<h5>單位： 仟, 佰, 拾, 亿, 仟, 佰, 拾, 万, 仟, 佰, 拾</h5>
	</div>
</template>

<script>
	export default {
		data: function() {
			return {
				inputVal:'',
				flag:false,
				values:''
			}
		},
		mounted() { //调用
		},
		methods: {
			shutDown() {
				this.flag = false
			},
			to_ch() {
				console.log(this.inputVal)
				this.inputVal = this.values
			}
		},
		watch: {
			inputVal(newVal, oldVal) {
				if (newVal.length == 13) {
					this.inputVal = oldVal
					this.flag = true
				}
			}
		},
		computed: {},
		filters: {
			//局部过滤器
			toChies: function(values) { //形参
				let len = values.length //统计出长度
				let arr = [];

				let chin_list = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'] //所有的数值对应的汉字

				let chin_lisp = ['仟', '佰', '拾', '亿', '仟', '佰', '拾', '万', '仟', '佰', '拾'] //进制

				for (let i = 0; i < len; i++) {
					arr.push(parseInt(values[i])); //输入的数据按下标存进去   存进去的只是数字
					arr[i] = chin_list[arr[i]] //是根据我们输入的输入的数字，对应着我们的chin_list这个数组
				} //123['壹','佰','贰','拾','叁']

				for (let i = len - 1, j = 1; i > 0; i--) { //i =2	1		//倒序		为了添加进制，方便我们去观看
					arr.splice(i, 0, chin_lisp[chin_lisp.length - j++]) //j=2
				}
				console.log(arr)

				arr = arr.join('')
				if (len >= 1) {
					arr += '元整'
				}
				return arr
			}
		}
	}
</script>

<style>
</style>
